package scala.pattern

/**
 * 匹配对象及样例类
 */
object MatchUnapplyTest1 {

  class User(val name: String, val age: Int)

  object User {
    def apply(name: String, age: Int): User = new User(name, age)

    def unapply(user: User) :Option[(String,Int)] ={
      if (user ==null){
        None
      }else{
        Some(user.name,user.age)
      }
    }



  }


  def main(args: Array[String]): Unit = {
    val user: User = User("zhangsan", 11)
    println(user match {
      case User("zhangsan",11) => "yes"
      case _=> "no"
    })
  }
}
